home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Apps / HighScoreEditor / EditingHSController.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  75 lines

  1.  
  2. #import "EditingHSController.h"
  3. #import <strings.h>
  4. #import <remote/NXProxy.h>
  5.  
  6. @implementation EditingHSController
  7.  
  8. - init
  9. {
  10.     [super init];
  11.     [self setGameName:[NXApp appName]];
  12.     return self;
  13. }
  14.  
  15. - displayHighScores:sender     // bring up high scores w/info loaded into it
  16. {
  17.     char *tempString = malloc(256);
  18.  
  19.     [super displayHighScores:sender];
  20.     sprintf(tempString, [strings valueForStringKey:"WindowTitle"],
  21.             gameName);
  22.     [highScorePanel setTitle:tempString];
  23.     free(tempString);
  24.     return self;
  25. }
  26.  
  27. - (const char *)gameName { return gameName; }
  28. - setGameName:(const char *)name
  29. {
  30.     if (gameName) free(gameName);
  31.     gameName = NXCopyStringBufferFromZone(name, [self zone]);
  32.     return self;
  33. }
  34.  
  35. - setLocalScores:(BOOL)flag
  36. {
  37.     HighScoreDistributor *distributor;
  38.     NXConnection *conn;
  39.     
  40.     if (flag == localScores) return self;
  41.     localScores = flag;
  42.     if (!localScores && !server) { // establish server connection
  43.         distributor = (HighScoreDistributor *)[NXConnection
  44.                 connectToName:"DAYHighScoreServer"
  45.                 onHost:serverHost fromZone:[self zone]];
  46.         if (!distributor) {
  47.             localScores = YES; // can't attach to server, so go local
  48.             NXRunAlertPanel("Score Server",
  49.                     [strings valueForStringKey:"noServer"],
  50.                     NULL, NULL, [strings valueForStringKey:"OK"]);
  51.             return self;
  52.         }
  53.         conn = [(NXProxy *)distributor connectionForProxy];
  54.         [conn registerForInvalidationNotification:self];
  55.         [conn runFromAppKit];
  56.         server = [distributor getServerFor:gameName];
  57.         if (!server) {
  58.             localScores = YES; // can't attach to server, so go local
  59.             NXRunAlertPanel("Score Server",
  60.                     [strings valueForStringKey:"noServer"],
  61.                     NULL, NULL, [strings valueForStringKey:"OK"]);
  62.             return self;
  63.         }
  64.         [server setProtocolForProxy:@protocol(HighScoreServer)];
  65.         [server clientCheckIn:self]; // let server know I'm here
  66.     }
  67.     if (localScores) [clearMenu setEnabled:YES];
  68.     else [clearMenu setEnabled:NO];
  69.     [self readHighScores];    // reload matrices
  70.     [self showHighScores];    // and then display the changes
  71.     return self;
  72. }
  73.  
  74. @end
  75.